function admin_business()
{
	//#################################################################
	//
	// 입력부
	//
	//#################################################################
	// 중복 체크
	$( '#btnCheckBusinessCode' ).click(function(e) {
        $.post( getGatePath()
		,
		{
			__key__: 'isSameBusinessCode',
			__returnType__: 'json',
			code: $( '#insertBusinessForm' ).find( 'input[name="code"]' ).val()
		}
		,
		function( data )
		{
			if( data.result == "SUCCESS" )
			{
				setResult( '[사업 관리코드 중복체크] 사용 가능한 코드' );
			}else{
				setResultFailForJSON( '[사업 관리코드 중복체크] 사용 불가능한 코드', data );
			}
		}
		,
		'json' );
    });
	
	// 모델 입력
	$( '#insertBusinessForm' ).submit(function(e) {
        e.preventDefault();
		
		var _formData = new FormData( document.getElementById( 'insertBusinessForm' ) );
		_formData.append( '__key__', 'insertBusiness' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[사업 추가] 성공' );
				}else{
					setResultFailForJSON( '[사업 추가] 실패', data );
				}
			}
		});
    });
	
	//#################################################################
	//
	// 조회부
	//
	//#################################################################
	// 목록 조회
	var _listPage 	= new PageInfo( document.getElementById( 'selectBusinesses' ) );
	$( "#businessRefresh" ).click(function(e) {
		selectAllBusinesses( _listPage.current, _listPage.numPerPage, businessRefreshSuccess, businessRefreshFail );
	});
	
	// 조회 성공
	function businessRefreshSuccess( data )
	{
		// 성공 핸들러
		setResult( '[사업 조회] 성공' );
		
		var $listContainer = $( "#selectBusinesses>.list" );
		// 비우기
		$listContainer.find( '.btnEdit' ).unbind( "click" );
		$listContainer.find( '.btnDelete' ).unbind( "click" );
		$listContainer.empty();
		
		// 타이틀 추가
		var _tr;
		_tr = "<thead>";
		_tr += "<tr>";
		_tr += 		"<td>NO</td>";
		_tr +=  	"<td>CODE</td>";
		_tr +=  	"<td>사업구분</td>";
		_tr +=  	"<td>사업명</td>";
		_tr +=  	"<td>제안 날짜</td>";		
		_tr +=  	"<td>결정 날짜</td>";
		_tr +=  	"<td>자료출처</td>";
		_tr +=  	"<td>EDIT</td>";
		_tr +=  	"<td>DELETE</td>";
		_tr += "</tr>";
		_tr += "</thead>";
		_tr += "<tbody>";
		// 리스트 추가
		var _no = (_listPage.current-1)*_listPage.numPerPage+1;
		for( var index in data.business )
		{
			var _item = data.business[ index ];
			_tr += "<tr>";
			_tr += 		"<td>"+(_no++)+"</td>";
			_tr += 		"<td>"+_item[ 'code' ]+"</td>";
			_tr += 		"<td>"+toStringByBusiness( _item[ 'b_code' ] )+"</td>";
			_tr += 		"<td>"+_item[ 'name' ]+"</td>";
			_tr += 		"<td>"+_item[ 'propose_date' ]+"</td>";			
			_tr += 		"<td>"+_item[ 'decision_date' ]+"</td>";
			_tr += 		"<td>"+_item[ 'ref' ]+"/"+_item[ 'ref_license' ]+"</td>";
			_tr += 		"<td>"+"<input type='button' class='btnEdit' value='EDIT' data='"+_item[ 'code' ]+"'/>"+"</td>";
			_tr += 		"<td>"+"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'code' ]+"'/>"+"</td>";
			_tr += "</tr>";
		}
		_tr += "</tbody>";
		$listContainer.append( _tr );
		
		// 수정 버튼 이벤트 등록
		$listContainer.find( '.btnEdit' ).bind( "click", null, function(e) {
			// alert( 'EDIT '+$(this).attr( 'data' ) );
			var $business_code = $(this).attr( 'data' );
			showUpdateBusinessPopup( $business_code );
		});
		// 삭제 버튼 이벤트 등록
		$listContainer.find( '.btnDelete' ).bind( "click", null, function(e) {
			alert( '미구현 :: DELETE '+$(this).attr( 'data' ) );
		});
		
		// 페이징
		_listPage.setTotalCount( data.count );
		_listPage.updateLabelField();
	}
	
	// 조회 실패
	function businessRefreshFail( data )
	{
		setResultFail( '[사업 조회] 실패', data );
	};
	
	// 상세 팝업 활성
	function showUpdateBusinessPopup( $business_code )
	{
		$.post( getGatePath(),
			{
				__key__: 'selectBusiness',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				businessCode: $business_code
			}, 
			function( data )
			{
				if( data.result == "SUCCESS" )
				{
					setResult( '[사업 상세 정보 조회] 성공' );
					
					// [[ 팝업 셋팅 ]]
					$popup = $( "#updateBusiness" );
					$popup.show();
					
					// 팝업이 설정과 동시에 공통변수 설정
					$popup.find( '.businessCode' ).val( data[ 'code' ] );
					
					$popup.find( '[name="code"]' ).val(		data[ 'code' ] );
					$popup.find( '[name="name"]' ).val( 	data[ 'name' ] );
					
					// 썸네일 정보
					var _thumbnails = null;
					if( data[ 'thumbnails' ] )
					{
						_thumbnails = data[ 'thumbnails' ][ 'thumb' ];
					}
					setPicture( $popup
								, null
								, _thumbnails );
					
					// 기타 설정
					$popup.find( '[name="bCode"]' ).val( 		data[ 'b_code' ] );
					$popup.find( '[name="name"]' ).val( 		data[ 'name' ] );
					$popup.find( '[name="pDate"]' ).val( 		data[ 'propose_date' ] );
					$popup.find( '[name="dDate"]' ).val( 		data[ 'decision_date' ] );					
					$popup.find( '[name="ref"]' ).val( 			data[ 'ref' ] );
					$popup.find( '[name="ref_license"]' ).val( 	data[ 'ref_license' ] );
					
					// 링크 정보
					selectBusinessLinks( data[ 'code' ] );
					// 태그 정보
					selectBusinessTags( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[사업 상세 정보 조회] 실패', data );
				}
			},
			'json' );
	}
	
	// 상세 팝업 수정
	$( '#updateBusinessForm' ).submit(function(e) {
		e.preventDefault();
		
		var _formData = new FormData( document.getElementById( 'updateBusinessForm' ) );
		_formData.append( '__key__', 'updateBusiness' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[사업 기본 정보 수정] 성공' );
					
					$( "#updateBusiness" ).hide();
					$( "#businessRefresh" ).click();
				}else{
					setResultFailForJSON( '[사업 기본 정보 수정] 실패', data );
				}
			}
		});
    });
	
	//#################################################################
	//
	// 사업 참조(링크)
	//
	//#################################################################
	// 1. 입력
	$( '#insertBusinessLinkForm' ).submit(function(e) {
        e.preventDefault();
		
		
		var _formData = new FormData( document.getElementById( 'insertBusinessLinkForm' ) );
		_formData.append( '__key__', 'insertBusinessLink' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[사업 링크 추가] 성공' );
					
					selectBusinessLinks( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[사업 링크 추가] 실패', data );
				}
			}
		});
    });
	// 2. 조회
	function selectBusinessLinks( $businessCode )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectBusinessLinks',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				businessCode: $businessCode
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[사업 링크 조회] 성공' );
					
					var $listContainer = $( '#businessLinks>.list' );
					// 비우기
					$listContainer.find( '.btnDelete' ).unbind( "click" );
					$listContainer.empty();
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>LINK</td>";
					_tr +=  	"<td>DELETE</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;
					for( var index in data.link )
					{
						var _item = data.link[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'link' ]+"</td>";
						_tr += 		"<td>"+"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'seq' ]+"'/>"+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$listContainer.append( _tr );
					
					// 삭제 버튼 이벤트 등록
					$listContainer.find( '.btnDelete' ).bind( "click", null, function(e) {
						var $link_seq = $(this).attr( 'data' );
						//alert( '미구현 :: DELETE '+$link_seq );
						deleteBusinessLink( $link_seq );
					});
				}else{
					setResultFailForJSON( '[사업 링크 조회] 실패', data );
				}
			}
			,
			'json' 
		);
	}
	// 3. 삭제
	function deleteBusinessLink( $link_seq )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'deleteBusinessLink',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				seq: $link_seq
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[사업 링크 삭제] 성공' );
					
					selectBusinessLinks( $( '#businessLinks' ).find( '.businessCode' ).val() );
				}else{
					setResultFailForJSON( '[사업 링크 삭제] 실패', data );
				}
			}
			,
			'json'
			);
	}
	
	//#################################################################
	//
	// 사업 참조(태그)
	//
	//#################################################################
	// 1. 입력
	$( '#insertBusinessTagForm' ).submit(function(e) {
        e.preventDefault();
		
		
		var _formData = new FormData( document.getElementById( 'insertBusinessTagForm' ) );
		_formData.append( '__key__', 'insertBusinessTag' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[사업 태그 추가] 성공' );
					
					selectBusinessTags( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[사업 태그 추가] 실패', data );
				}
			}
		});
    });
	// 2. 조회
	function selectBusinessTags( $businessCode )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectBusinessTags',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				businessCode: $businessCode
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[사업 태그 조회] 성공' );
					
					var $listContainer = $( '#businessTags>.list' );
					// 비우기
					$listContainer.find( '.btnDelete' ).unbind( "click" );
					$listContainer.empty();
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>TAG</td>";
					_tr +=  	"<td>DELETE</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;
					for( var index in data.tag )
					{
						var _item = data.tag[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'tag' ]+"</td>";
						_tr += 		"<td>"+"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'seq' ]+"'/>"+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$listContainer.append( _tr );
					
					// 삭제 버튼 이벤트 등록
					$listContainer.find( '.btnDelete' ).bind( "click", null, function(e) {
						var $seq = $(this).attr( 'data' );
						//alert( '미구현 :: DELETE '+$seq );
						deleteBusinessTag( $seq );
					});
				}else{
					setResultFailForJSON( '[사업 태그 조회] 실패', data );
				}
			}
			,
			'json' 
		);
	}
	// 3. 삭제
	function deleteBusinessTag( $seq )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'deleteBusinessTag',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				seq: $seq
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[사업 태그 삭제] 성공' );
					
					selectBusinessTags( $( '#businessTags' ).find( '.businessCode' ).val() );
				}else{
					setResultFailForJSON( '[사업 태그 삭제] 실패', data );
				}
			}
			,
			'json'
			);
	}
	// 4. 샘플 태그 가져오기
	$( '.btn_getAllBusinessTags' ).click(function(e) {
        e.preventDefault();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectAllBusinessTags',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session()
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모든 사업 태그 조회] 성공' );
					
					var $selectBox = $( '.selectBusinessTag' ).empty();
					for( var idx in data.tag )
					{
						var _tag = data.tag[ idx ];
						var _sItem = '<option value="'+_tag+'">'+_tag+'</option>';
						$selectBox.append( _sItem );
					}
				}else{
					setResultFailForJSON( '[모든 사업 태그 조회] 실패', data );
				}
			}
			,
			'json' );
    });
	// 한번 가져오기
	$( '.btn_getAllBusinessTags' ).click();
	$( '.selectBusinessTag' ).change(function(e) {
        var _txt = $( e.target ).parentsUntil( 'div' ).find( 'input[type=text][name=tag]' );
		_txt.val( $( e.target ).val() );
    });
	
	
	
	//#################################################################
	//
	// http://data.popong.com/ 에서 가져오기
	//
	//#################################################################
	var _popongSearchPage 	= 1;
	$('#searchBusinessByPopongForm' ).submit(function(e) {
        e.preventDefault();
		
		_popongSearchPage = 1;
		
		searchBusinessByPopong();
	})
	
	function searchBusinessByPopong()
	{	
		var _name = $( '#searchBusinessByPopongForm>[name="name"]' ).val(); 
		$.get(
			'popong/searchBusiness.php'
			,
			{
				name: _name,
				page: _popongSearchPage,
				per_page: 20
			}
			,
			function( data )
			{
				// 조회됨.
				/*
				assembly_id: 18
				decision_date: "2012-05-29"
				document_url: null
				id: "1805866"
				is_processed: true
				link_id: "PRC_B0I9O0E9Y0G3J1N7A1Y2H5S8E7Z5S3"
				name: "「4대강 살리기 사업」 예비타당성조사 요구안"
				proposed_date: "2009-09-03"
				sponsor: "유성엽의원등 18인"
				status: "임기만료폐기"
				status_id: 15
				status_ids: [1, 2, 15]
				summary: null
				*/
				
				var $listContainer = $( '#searchBusinessByPopong>.list' );
				// 비우기
				$listContainer.find( '.btnSelect' ).unbind( "click" );
				$listContainer.empty();
				
				// 타이틀 추가
				var _tr;
				_tr = "<thead>";
				_tr += "<tr>";
				_tr += 		"<td>NO</td>";
				_tr +=  	"<td>이름</td>";
				_tr +=  	"<td>제안일</td>";
				_tr +=  	"<td>결정일</td>";
				_tr +=  	"<td>관련링크</td>";
				_tr +=  	"<td>상태</td>";
				_tr +=  	"<td>SELECT</td>";
				_tr += "</tr>";
				_tr += "</thead>";
				_tr += "<tbody>";
				// 리스트 추가
				var _no = 1;
				for( var i in data.items )
				{
					var _item = data.items[ i ];
					_tr += "<tr>";
					_tr += 		"<td>"+(_no++)+"</td>";
					_tr += 		"<td>"+_item[ 'name' ]+"</td>";
					_tr += 		"<td>"+_item[ 'proposed_date' ]+"</td>";	
					_tr += 		"<td>"+_item[ 'decision_date' ]+"</td>";				
					_tr += 		"<td>"+"<a href='"+_item[ 'document_url' ]+"' target='_blank'>LINK</a>"+"</td>";
					_tr += 		"<td>"+_item[ 'status' ]+"</td>";
					_tr += 		"<td>"+"<input type='button' class='btnSelect' value='SELECT' data='"+i+"'/>"+"</td>";
					_tr += "</tr>";
				}
				_tr += "</tbody>";
				$listContainer.append( _tr );
				
				// 삭제 버튼 이벤트 등록
				$listContainer.find( '.btnSelect' ).bind( "click", null, function(e) {
					var $index = parseInt( $(this).attr( 'data' ) );
					// $index 번째 선택됨... > 
					var $model = data.items[ $index ];
					var $form = $( '#insertBusinessForm' );
					
					$form.find( '[name="code"]' ).val( $model[ 'id' ] );
					$form.find( '[name="name"]' ).val( $model[ 'name' ] );
					$form.find( '[name="pDate"]' ).val( $model[ 'proposed_date' ] );
					$form.find( '[name="dDate"]' ).val( $model[ 'decision_date' ] );
					$form.find( '[name="ref"]' ).val( 'data.popong.com' );
					$form.find( '[name="ref_license"]' ).val( 'CC-BY 4.0' );
				});
						
				// 페이징
				$prevButton = $("#btn_prevSearchBusinessByPopong" );
				$nextButton = $("#btn_nextSearchBusinessByPopong" );
				if( data[ 'prev_page' ] == undefined )
				{
					// 이전 버튼 숨기기
					$prevButton.hide();
				}else{
					$prevButton.show();
					$prevButton.val( "PREV PAGE "+data[ 'prev_page' ] );
				}
				if( data[ 'next_page' ] == undefined )
				{
					// 이전 버튼 숨기기
					$nextButton.hide();
				}else{
					$nextButton.show();
					$nextButton.val( "NEXT PAGE "+data[ 'next_page' ] );
				}
				
				$prevButton.unbind( 'click' );
				$prevButton.click( function( e )
				{
					_popongSearchPage--;
					
					searchBusinessByPopong();
				});
				$nextButton.unbind( 'click' );
				$nextButton.click( function( e )
				{
					_popongSearchPage++;
					
					searchBusinessByPopong();
				});				
			}
			,
			'json' );
    }
}